<?php

namespace app\admin\controller;
use think\Controller;
use think\Db;
class System extends Controller{

    public $user;

    /*
	*	构造函数
	*/
    function __construct(){
        parent::__construct();
        $this->requestData = $this->request->param('');
        $this->user['shopid'] = $this->requestData['shop_id'];
    }

    public function  tell(){
        if (!isset($this->requestData['tell']) || empty($this->requestData['tell'])) return array('message'=>'请填写订餐电话');
        if (!is_array($this->requestData['tell']))  return array('message'=>'请传数组');
        $tell=implode(",",$this->requestData['tell']);
        // $tell=serialize($this->requestData['tell']);
        $pass['tell']=$tell;
        $shop_id= $this->user['shopid'];
        $res= db('shop')->where("id='$shop_id'")->update($pass);
        if ($res === false) return array("message" => '操作失败');
    }

    public function  open(){
        $shop_id= $this->user['shopid'];
        $db_shop=db("shop");
        $shop= $db_shop->where("id='$shop_id'")->field("isopen")->find();
        if($shop['isopen']==0){
            $data['isopen']=1;
        }else{
            $data['isopen']=0;
        }
        $res=$db_shop->where("id='$shop_id'")->update($data);
        if(!$res) return array("message"=>'系统繁忙');
        return $data;
    }

    public function  des(){
        if (!isset($this->requestData['des'])) return array('message'=>'请填写简介');
        $pass['des']=$this->requestData['des'];
        $shop_id= $this->user['shopid'];
        $res= db('shop')->where("id='$shop_id'")->update($pass);
        if ($res === false) return array("message" => '操作失败');
    }

    public function  book(){
        $shop_id= $this->user['shopid'];
        $db_shop=db('shop');
        $shop= $db_shop->field('isbook')->where("id='$shop_id'")->find();
        if($shop['isbook']==0){
            $data['isbook']=1;
        }else{
            $data['isbook']=0;
        }
        $res= $db_shop->where("id='$shop_id'")->update($data);
        if ($res === false) return array("message" => '操作失败');
        return $data;
    }

    public function  send(){
        $shop_id= $this->user['shopid'];
        $db_shop=db('shop');
        $shop= $db_shop->field('issend')->where("id='$shop_id'")->find();
        $data['send_fee']=$this->requestData['fee'];
        if($shop['issend']==0){
            $data['issend']=1;
        }else{
            $data['issend']=0;
        }
        $res= $db_shop->where("id='$shop_id'")->update($data);
        if ($res === false) return array("message" => '操作失败');
        return $data;
    }

    public function full_distribution(){
        if (!isset($this->requestData['full_distribution'])) return array('message'=>'请填写配送费');
        $pass['full_distribution']=$this->requestData['full_distribution'];
        $shop_id= $this->user['shopid'];
        $res= db('shop')->where("id='$shop_id'")->update($pass);
        if ($res === false) return array("message" => '操作失败');
    }
}